/**
 * Created by LeungZ on 2016/9/8.
 */
class Image {
    constructor(imageSrv, list, ctgNotification) {
        "ngInject";
        this._imageSrv = imageSrv;
        this._notification = ctgNotification;

        this.imageTypeList = [{name: '全部', type: null}, {name: '基础镜像', type: '001'}, {name: '应用镜像', type: '002'}];
        this.filter = {
            imageName: null,
            imageType: null
        };
        this.page = {
            currentPage: 1,
            totalItems: 0
        };
        if (list) {
            this.table = list.list;
            this.page.totalItems = list.total;
        } else this.table = [];
    }

    getList() {
        this.table = null;
        this._imageSrv.getImageList({currentPage: this.page.currentPage}, this.filter).then(data=> {
            this.table = data.list;
            this.page.totalItems = data.total;
        }).catch(()=> {
            this.table = [];
            this.page.totalItems = 0;
            this._notification.error('获取Docker镜像列表数据有误.');
        });
    }

    search() {
        this.page.currentPage = 1;
        this.getList();
    }

    setImageType(type) {
        this.filter.imageType = type;
        this.search();
    }

}
export default Image;